
struct.o:     file format elf32-littlearm


Disassembly of section .text:

00000000 <main>:
	char a3[6];
	char a4[8];
}aaa;

int main()
{
   0:	e92d4800 	push	{fp, lr}
   4:	e28db004 	add	fp, sp, #4
   8:	e24dd028 	sub	sp, sp, #40	; 0x28
	char buf[30];
	
	memset(buf, '0', sizeof(buf));
   c:	e24b3028 	sub	r3, fp, #40	; 0x28
  10:	e3a0201e 	mov	r2, #30
  14:	e3a01030 	mov	r1, #48	; 0x30
  18:	e1a00003 	mov	r0, r3
  1c:	ebfffffe 	bl	0 <memset>
	strcpy(buf,"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  20:	e24b3028 	sub	r3, fp, #40	; 0x28
  24:	e59f20f4 	ldr	r2, [pc, #244]	; 120 <main+0x120>
  28:	e1a0c003 	mov	ip, r3
  2c:	e1a0e002 	mov	lr, r2
  30:	e8be000f 	ldm	lr!, {r0, r1, r2, r3}
  34:	e8ac000f 	stmia	ip!, {r0, r1, r2, r3}
  38:	e89e0007 	ldm	lr, {r0, r1, r2}
  3c:	e8ac0003 	stmia	ip!, {r0, r1}
  40:	e1cc20b0 	strh	r2, [ip]
  44:	e28cc002 	add	ip, ip, #2
  48:	e1a03822 	lsr	r3, r2, #16
  4c:	e5cc3000 	strb	r3, [ip]
	
	printf("buf length : %d\n", sizeof(buf));
  50:	e3a0101e 	mov	r1, #30
  54:	e59f00c8 	ldr	r0, [pc, #200]	; 124 <main+0x124>
  58:	ebfffffe 	bl	0 <printf>
	printf("struct length : %d\n", sizeof(struct aaa));
  5c:	e3a01010 	mov	r1, #16
  60:	e59f00c0 	ldr	r0, [pc, #192]	; 128 <main+0x128>
  64:	ebfffffe 	bl	0 <printf>
	
	aaa *aa;
	aa = (struct aaa*)buf;
  68:	e24b3028 	sub	r3, fp, #40	; 0x28
  6c:	e50b3008 	str	r3, [fp, #-8]
	
	// 按照结构里的类型填充各个字段.
	printf("a1 is %d\n", aa->a1);
  70:	e51b3008 	ldr	r3, [fp, #-8]
  74:	e5d33000 	ldrb	r3, [r3]
  78:	e1a01003 	mov	r1, r3
  7c:	e59f00a8 	ldr	r0, [pc, #168]	; 12c <main+0x12c>
  80:	ebfffffe 	bl	0 <printf>
	printf("a1 is %c\n", aa->a1);
  84:	e51b3008 	ldr	r3, [fp, #-8]
  88:	e5d33000 	ldrb	r3, [r3]
  8c:	e1a01003 	mov	r1, r3
  90:	e59f0098 	ldr	r0, [pc, #152]	; 130 <main+0x130>
  94:	ebfffffe 	bl	0 <printf>
	//printf("a1 is %s\n", aa->a1);	Segmentation fault. 因为字段是单个字节.	2012/11/1
	
	printf("a2 is %d\n", aa->a2);
  98:	e51b3008 	ldr	r3, [fp, #-8]
  9c:	e5d33001 	ldrb	r3, [r3, #1]
  a0:	e1a01003 	mov	r1, r3
  a4:	e59f0088 	ldr	r0, [pc, #136]	; 134 <main+0x134>
  a8:	ebfffffe 	bl	0 <printf>
	printf("a2 is %c\n", aa->a2);
  ac:	e51b3008 	ldr	r3, [fp, #-8]
  b0:	e5d33001 	ldrb	r3, [r3, #1]
  b4:	e1a01003 	mov	r1, r3
  b8:	e59f0078 	ldr	r0, [pc, #120]	; 138 <main+0x138>
  bc:	ebfffffe 	bl	0 <printf>
	//printf("a2 is %s\n", aa->a2);	Segmentation fault	因为字段是单个字节.

	printf("a3 is %s\n", aa->a3);		// why not overflow, xiaozhi? 因为被转换成了指针
  c0:	e51b3008 	ldr	r3, [fp, #-8]
  c4:	e2833002 	add	r3, r3, #2
  c8:	e1a01003 	mov	r1, r3
  cc:	e59f0068 	ldr	r0, [pc, #104]	; 13c <main+0x13c>
  d0:	ebfffffe 	bl	0 <printf>
	printf("a4 is %s\n", aa->a4);		// ditto
  d4:	e51b3008 	ldr	r3, [fp, #-8]
  d8:	e2833008 	add	r3, r3, #8
  dc:	e1a01003 	mov	r1, r3
  e0:	e59f0058 	ldr	r0, [pc, #88]	; 140 <main+0x140>
  e4:	ebfffffe 	bl	0 <printf>

	printf("a3 is %.6s\n", aa->a3);
  e8:	e51b3008 	ldr	r3, [fp, #-8]
  ec:	e2833002 	add	r3, r3, #2
  f0:	e1a01003 	mov	r1, r3
  f4:	e59f0048 	ldr	r0, [pc, #72]	; 144 <main+0x144>
  f8:	ebfffffe 	bl	0 <printf>
	printf("a4 is %.8s\n", aa->a4);
  fc:	e51b3008 	ldr	r3, [fp, #-8]
 100:	e2833008 	add	r3, r3, #8
 104:	e1a01003 	mov	r1, r3
 108:	e59f0038 	ldr	r0, [pc, #56]	; 148 <main+0x148>
 10c:	ebfffffe 	bl	0 <printf>
	
	return 0;
 110:	e3a03000 	mov	r3, #0
}
 114:	e1a00003 	mov	r0, r3
 118:	e24bd004 	sub	sp, fp, #4
 11c:	e8bd8800 	pop	{fp, pc}
 120:	00000000 	.word	0x00000000
 124:	0000001c 	.word	0x0000001c
 128:	00000030 	.word	0x00000030
 12c:	00000044 	.word	0x00000044
 130:	00000050 	.word	0x00000050
 134:	0000005c 	.word	0x0000005c
 138:	00000068 	.word	0x00000068
 13c:	00000074 	.word	0x00000074
 140:	00000080 	.word	0x00000080
 144:	0000008c 	.word	0x0000008c
 148:	00000098 	.word	0x00000098
